﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Lead2012.Business
{
    public class MappingFieldRepository
    {
        // Create an instance of entity
        Lead2012Entities entities = new Lead2012Entities();
        
        public MappingField GetSingle(int id)
        {
            return (from _object in entities.MappingFields where _object.FieldId == id select _object).FirstOrDefault();
        }

        public void Create(MappingField _object)
        {
            entities.AddToMappingFields(_object);
            entities.SaveChanges();
        }

        public void Update(MappingField _object)
        {
            entities.SaveChanges();
        }
        public void Delete(int id)
        {
            var _object = (from _list in entities.MappingFields where _list.MappingId == id select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }
        public void Save(MappingField _object)
        {
            _object.EntityKey = (from MappingField ac in entities.MappingFields where ac.MappingId == _object.MappingId select ac).FirstOrDefault().EntityKey;
            entities.SaveChanges();
        }
    }
}